package com.netmi.myuploadfileretrofit.utils;

import android.app.Activity;
import android.os.Environment;
import android.util.Log;

import com.netmi.myuploadfileretrofit.MainActivity;

import java.io.File;

/**
 * 类描述：文件操作
 * 创建人：tgw
 * 创建时间：2020/7/28
 * 修改备注：
 */
public class Fileutils {

    private static String TAG = "tgw" + Fileutils.class.getSimpleName();

    public static String getVideoOutCompressPath(String videoPath, Activity context) {
        String path = null;
        File file = null;
        long tag = System.currentTimeMillis();
        if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {//SDCard是否可用
            //最好把images替换成你的项目名称，避免有重复文件夹
            path = context.getExternalFilesDir(Environment.DIRECTORY_MOVIES) + File.separator + "videoCompress/";
            file = new File(path);
            if (!file.exists()) {
                file.mkdirs();
            }
            Log.d(TAG, "compressVideo getVideoOutCompressPath--- getExternalFilesDir(Environment.DIRECTORY_MOVIES): " + context.getExternalFilesDir(Environment.DIRECTORY_MOVIES).getAbsolutePath());
            path = context.getExternalFilesDir(Environment.DIRECTORY_MOVIES) + File.separator + "videoCompress/" + tag + ".mp4";
        } else {
            Log.d(TAG, " compressVideo getVideoOutCompressPath---getFilesDir: " + context.getFilesDir().getAbsolutePath());
            path = context.getFilesDir() + File.separator + "videoCompress/";
            file = new File(path);
            if (!file.exists()) {
                file.mkdirs();
            }
            path = context.getFilesDir() + File.separator + "videoCompress/" + tag + ".mp4";
        }
        Log.d(TAG, "compressVideo getVideoOutCompressPath---最终路径: " + path);

        return path;

    }
}
